package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SourceOfLeadCustomers;
import com.ruoyi.system.service.ISourceOfLeadCustomersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线索客户来源Controller
 *
 * @author ruoyi
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/system/customers")
public class SourceOfLeadCustomersController extends BaseController
{
    @Autowired
    private ISourceOfLeadCustomersService sourceOfLeadCustomersService;

    /**
     * 查询线索客户来源列表
     */
    //@PreAuthorize("@ss.hasPermi('system:customers:list')")
    @GetMapping("/list")
    public TableDataInfo list(SourceOfLeadCustomers sourceOfLeadCustomers)
    {
        startPage();
        List<SourceOfLeadCustomers> list = sourceOfLeadCustomersService.selectSourceOfLeadCustomersList(sourceOfLeadCustomers);
        return getDataTable(list);
    }

    /**
     * 导出线索客户来源列表
     */
    @PreAuthorize("@ss.hasPermi('system:customers:export')")
    @Log(title = "线索客户来源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SourceOfLeadCustomers sourceOfLeadCustomers)
    {
        List<SourceOfLeadCustomers> list = sourceOfLeadCustomersService.selectSourceOfLeadCustomersList(sourceOfLeadCustomers);
        ExcelUtil<SourceOfLeadCustomers> util = new ExcelUtil<SourceOfLeadCustomers>(SourceOfLeadCustomers.class);
        util.exportExcel(response, list, "线索客户来源数据");
    }

    /**
     * 获取线索客户来源详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:customers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sourceOfLeadCustomersService.selectSourceOfLeadCustomersById(id));
    }

    /**
     * 新增线索客户来源
     */
    @PreAuthorize("@ss.hasPermi('system:customers:add')")
    @Log(title = "线索客户来源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SourceOfLeadCustomers sourceOfLeadCustomers)
    {
        return toAjax(sourceOfLeadCustomersService.insertSourceOfLeadCustomers(sourceOfLeadCustomers));
    }

    /**
     * 修改线索客户来源
     */
    @PreAuthorize("@ss.hasPermi('system:customers:edit')")
    @Log(title = "线索客户来源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SourceOfLeadCustomers sourceOfLeadCustomers)
    {
        return toAjax(sourceOfLeadCustomersService.updateSourceOfLeadCustomers(sourceOfLeadCustomers));
    }

    /**
     * 删除线索客户来源
     */
    @PreAuthorize("@ss.hasPermi('system:customers:remove')")
    @Log(title = "线索客户来源", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sourceOfLeadCustomersService.deleteSourceOfLeadCustomersByIds(ids));
    }
}